package com.example.a2306_shop.main

import androidx.lifecycle.viewModelScope
import com.example.lib_base.entity.ProductEntity
import com.example.lib_base.entity.Res
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.utils.SingleLiveData
import kotlinx.coroutines.launch

class MainViewModel:BaseViewModel() {
    //商品列表
    val productSuccess = SingleLiveData<Res<ProductEntity>>()
    val productFail = SingleLiveData<String>()
    fun product(keyword:String,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                productSuccess.postValue(apiService.product(keyword, limit, page))
            } catch (e: Exception) {
                productFail.postValue(e.message.toString())
            }
        }
    }
}